package com.bjsxt.listener;
import javax.servlet.ServletContext;
/**
 * 用于销毁session
 */
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.bjsxt.po.Admin;


@WebListener
public class MysessionListener implements HttpSessionListener {

   
    public MysessionListener() {
        
    }
    /**
     * 在创建的时候触发
     */
    public void sessionCreated(HttpSessionEvent arg0)  { 
         
    }

	/**
	 * 对在全局容器中的对象进行销毁
	 */
    public void sessionDestroyed(HttpSessionEvent sessionEvent)  { 
    	HttpSession session = sessionEvent.getSession();
		ServletContext sc = session.getServletContext();
	    Admin admin=(Admin) session.getAttribute("admin");
	    if(admin!=null)
	    sc.removeAttribute(admin.getUsername());

    }
	
}
